<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class setting extends CI_Controller {
	var $data = array();

	public function __construct() {
		parent::__construct();

		$this -> output -> cache(0);
		$this -> data['current_module'] = site_url("setting");
		$this->data['nowmenu']="setting";
		$this->data['title']="Setting";
		$this->data['role_id']=$this -> session -> userdata('role_id');
	}

	public function index() {
		$this -> load -> view('setting/main', $this -> data);
	}

	public function role_index() {
		$query = $this -> db -> query("SELECT roleid,name FROM  `role`");
		$role_type=array();
		foreach ($query->result() as $row) {
			$role_type[$row->roleid] = $row->name;
		}
		$this -> data['role_type']=$role_type;
		$this -> load -> view('setting/role_setting', $this -> data);
	}

	public function getroledata() {
		$query = $this -> db -> query("SELECT * FROM  `role`");
		echo $query -> result_array();
	}

	public function getuserdetail() {
		$query = $this -> db -> query("SELECT * FROM  `Users` where UUID=".$_REQUEST['UUID']);
		echo json_encode($query -> result_array());
	}
	public function deleteuser()
	{
		$this -> db -> delete('Users', array('UUID' => $_REQUEST['UUID']));
	}
	public function saveuser() {
		

			
		$data = array('Username' => $_REQUEST['username'], 'Name' => $_REQUEST['Firstname']
		,'Lastname'=>$_REQUEST['Lastname']
		, 'Password' => $_REQUEST['Password'], 'Email' => $_REQUEST['Email']
		, 'Block' => $_REQUEST['Block'], 'roleid' => $_REQUEST['Usertype']);
		if ($_REQUEST['uid'] != "0") {
			$this -> db -> update('Users', $data, "UUID =" . $_REQUEST['uid']);
			echo "Update Complete";
		} else {
			$this -> db -> insert('Users', $data);
			echo "Add Complete";
		}

	}

	public function get_user_list() {
		$query = $this -> db -> query("SELECT Users.uuid,Users.name,Users.lastname,Users.username,role.name from Users INNER JOIN role ON role.roleid=Users.roleid");

		echo json_encode($query -> result_array());
	}

}
?>